﻿<%@ Import Namespace="ASPUPLOADLib" %>
<%@ Import Namespace="System.Reflection" %> 


<!--#include file="isLogin.aspx"-->
<%
dim mmArt
dim mmUpload,File,uploadedFileURL

isMorethanMaxFileSize=false

uploadedFileURL=SaveFile()
%>

<script language="vbscript" runat="server">
dim isMorethanMaxFileSize as boolean
dim CanSave as boolean

Function SaveFile()
	SaveFile = SaveFileByASPUpload()
End Function


Function SaveFileByASPUpload()
	dim fileExName as string,WebNote_ImgUploadPath as string,fileName as string
	Dim MyFileColl As HttpFileCollection = Request.Files
	Dim MyPostedFile As HttpPostedFile = MyFileColl.Get(0)
	Dim MyFileName As String = MyPostedFile.FileName
	dim mmArt=New WebNote.WebNote()
	fileExName=mmArt.getFileExtensionName(MyFileName)
	if mmArt.CheckFileType(allow_upload_file_ext,mmArt.getFileExtensionName(fileExName)) then
		WebNote_ImgUploadPath=mmArt.DirectionPath
		mmArt.MD(Server.mappath(WebNote_ImgUploadPath))
		fileName=getAutoName() & "." & fileExName
				
		MyPostedFile.SaveAs(server.mappath(WebNote_ImgUploadPath & "/" & fileName ))
		SaveFileByASPUpload=WebNote_ImgUploadPath &  "/" & fileName
		CanSave=true
	end if
	mmArt=Nothing
End Function

Function ASPNetFileNameEncode(sFileName)
	dim returnValue
	dim TempStr,i,iCode,AsciCode

	for i=1 to len(sFileName)
		iCode = Mid(sFileName,i,1)
		AsciCode = AscW(iCode)
		if AsciCode <-1 or AsciCode >200 then
			TempStr=TempStr & math.ABS(AsciCode)
		else
			TempStr=TempStr & iCode
		end if
	next
	ASPNetFileNameEncode=TempStr
End Function

Function FileExists(sFilePath) as boolean
	Dim FSO As System.IO.File
	FileExists=FSO.Exists(Server.Mappath(sFilePath))
	FSO = Nothing
End Function

function getAutoName() as string
	dim a
	Randomize
	a=Now()
	getAutoName=Year(a) & Month(a) & day(a) & Minute(a) & hour(a) & second(a) & Int((99 * Rnd) + 1)
end function
</script>
<script language="javascript" type="text/javascript">
var cansave=<%=Lcase(CanSave)%>,isMorethanMaxFileSize=<%=Lcase(isMorethanMaxFileSize)%>
if (cansave)
{
	window.top.document.getElementById("UpLoadStatus").innerText="upload finished";
	window.top.__Close("<%=uploadedFileURL%>");
}
else
{
	if (isMorethanMaxFileSize)
	{
		window.top.CannotSave();
	}
	else
	{
		window.top.RaiseError1();
	}
	history.go(-1);
}
</script>